package com.shengruan.admin.action;

import com.shengruan.admin.jdbc.SubscriptionEmailJdbc;
import com.shengruan.admin.vo.SubscriptionEmail;
import com.shengruan.common.BaseAction;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author <a href="mailto:zhdqCN@gmail.com">DaQing Zhou</a>
 * @version 1.0
 * @CreationTime: 12-7-6 下午1:53
 * @Description: To change this template use File | Settings | File Templates.
 */
public class SubscriptionEmailAction extends BaseAction {

    Logger logger = LoggerFactory.getLogger(getClass());

    private SubscriptionEmailJdbc subscriptionEmailJdbc = (SubscriptionEmailJdbc) this.getJdbc(SubscriptionEmailJdbc.class);

    public void list() throws Exception {
        List<SubscriptionEmail> subscriptionEmailList = this.subscriptionEmailJdbc.getList();
        this.setRequest("subscriptionEmailList", subscriptionEmailList);
        this.forward("/admin/article/subscription-email-list.jsp");
    }

    public void subscriptionEmail() throws Exception {
        String email = StringUtils.trim(this.input("email"));
        SubscriptionEmail subscriptionEmail = this.subscriptionEmailJdbc.getByEmail(email);
        if (null == subscriptionEmail) {
            subscriptionEmail = new SubscriptionEmail();
            subscriptionEmail.setEmail(email);
            subscriptionEmail.setCreateTime(System.currentTimeMillis() + "");
            this.subscriptionEmailJdbc.save(subscriptionEmail);
            this.print("success");
        } else {
            this.print("exist");
        }
    }
}
